﻿Imports System.Data.OleDb
Public Class addnewskincare
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub AddNew_Click(ByVal sender As Object, ByVal e As EventArgs) Handles AddNew.Click

        Dim newFileName As String
        newFileName = Guid.NewGuid().ToString() & getSuffix(images.FileName)
        If images.HasFile Then
            images.SaveAs(Server.MapPath("pictures") & "/" & newFileName)
        End If



        Dim sql As String = "INSERT INTO [skin care] ([Skin Care Center Name],[Postcode],[Skin Care Physician],[Physician Details],[Website],[Phone Number],[Care Center Images],[Consult fee],[Rating Stars]) VALUES (@f1,@f2,@f3,@f4,@f5,@f6,@f7,@f8,@f9)"
        Dim conn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("skinConnectionstring").ConnectionString)
        Dim cmd As OleDbCommand = New OleDbCommand(sql, conn)
        cmd.Parameters.AddWithValue("@f1", tb_name.Text)
        cmd.Parameters.AddWithValue("@f2", tb_postcode.Text)
        cmd.Parameters.AddWithValue("@f3", tb_scp.Text)
        cmd.Parameters.AddWithValue("@f4", tb_pd.Text)
        cmd.Parameters.AddWithValue("@f5", tb_website.Text)
        cmd.Parameters.AddWithValue("@f6", tb_pn.Text)
        cmd.Parameters.AddWithValue("@f7", "pictures/" & newFileName)
        cmd.Parameters.AddWithValue("@f8", tb_cf.Text)
        cmd.Parameters.AddWithValue("@f9", rbl_stars.SelectedValue)
        conn.Open()
        cmd.ExecuteNonQuery()
        conn.Close()
        cmd.Dispose()
        conn.Dispose()
        Response.Redirect("list.aspx")

    End Sub

    Function getSuffix(ByVal fn As String)
        Dim fileParts = fn.Split(".")
        Dim suffix = fileParts(fileParts.Length - 1)
        Return "." & suffix
    End Function
End Class